Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataViews: Avoid double click handler on primary fields #67393

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

youknowriad
Copy link
Contributor

Follow up to #67199

What?

That PR highlighted a hidden bug in DataViews where clicking primary fields triggered both "onClick" handler and "onSelectionChange". This PR prevents that by stopping the propagation of the event.

Testing Instructions

1- Open the "pages" page in the site editor.
2- Switch to table view.
3- Click on the "title" of a page.
4- You should navigate to the editor.

@youknowriad youknowriad added the [Type] Bug An existing feature does not function as intended label Nov 28, 2024
@youknowriad youknowriad self-assigned this Nov 28, 2024
Copy link

github-actions bot commented Nov 28, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: gigitux <gigitux@git.wordpress.org>
Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Contributor

@gigitux gigitux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Should we add a comment that explains why event.preventDefault() and event.stopPropagation() are necessary?

@youknowriad youknowriad enabled auto-merge (squash) November 28, 2024 16:34
@youknowriad youknowriad added the [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond label Nov 28, 2024
Copy link

Flaky tests detected in 59708ba.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12072670743
📝 Reported issues:

onKeyDown: ( event: React.KeyboardEvent ) => {
if ( event.key === 'Enter' || event.key === '' ) {
event.preventDefault();
event.stopPropagation();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These calls should be in the onClickItem handler. If the dataview doesn't specify any onClickItem handler, the default one does nothing and you want the event to bubble up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's actually a few more issues where the classnames, role... shouldn't be added if there's no onClickItem. I'll open a follow-up.

@youknowriad youknowriad merged commit 6a989b4 into trunk Nov 28, 2024
66 checks passed
@youknowriad youknowriad deleted the avoid/double-click-handler branch November 28, 2024 17:08
@github-actions github-actions bot added this to the Gutenberg 19.9 milestone Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants